<?php
namespace App\Models;

use App\Exceptions\ApiException;
use Illuminate\Database\Eloquent\Model;

class CommonModel extends Model {
	// 定义不能被批量复制的字段，create() ，参考模型赋值文档
	protected $guarded = [];
	
	
	public function scopePages($query){
		$page = request()->input('page',1);

		if($page < 1){
			$page = 1;
		}
		$page_size = config('basic.page_size');
		$offset = ($page - 1) * $page_size;
		$data = $query->offset($offset)->limit($page_size)->get();
		return $data;
	}
}